package com.hdl.servlet.user;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.hdl.entity.HdlUser;
import com.hdl.service.UserService;
import com.hdl.service.impl.UserServiceImpl;
import com.hdl.util.UploadLogUtil;

/**
 * UpdateLogServlet 修改用户头像
 * @author 白云苍狗
 *
 */
@WebServlet("/updateLog.let")
public class UpdateLogServlet extends HttpServlet{
	
	private UserService service = new UserServiceImpl();
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		//新建用户对象
		HdlUser newUser = new HdlUser();
		
		//封装
		UploadLogUtil.upload(req, resp, newUser);
		
		//从session中获取用户对象
		HdlUser user = (HdlUser) req.getSession().getAttribute("user");
		user.setHdlUserLog(newUser.getHdlUserLog());
		try {
		//调用用户业务逻辑层方法
		service.update(user);
		}catch(Exception e) {
			e.printStackTrace();
		}
		//重新存入session
		req.getSession().setAttribute("user", user);
		//转发
		req.getRequestDispatcher("/usercenter/user2.jsp").forward(req, resp);
		
	}
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
}
